﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ScoreMS.Model;

namespace ScoreMS.BLL
{
    /// <summary>
    /// 详细分数(每小题)，事务逻辑
    /// </summary>
    public class Score_detailBS
    {
        /// <summary>
        /// 获取单个小题分数
        /// </summary>
        /// <param name="student_id">学生学号</param>
        /// <param name="problem_id">小题ID</param>
        /// <returns></returns>
        static public int GetScore(string student_id, int problem_id)
        {
            using (scoremsdbEntities db = new scoremsdbEntities())
            {
                var score_detail = db.score_detail.FirstOrDefault(x => x.student_id == student_id && x.problem_id == problem_id);
                return score_detail.score_detail_points;
            }
        }
        /// <summary>
        /// 获取单个Model.Score_detail
        /// </summary>
        /// <param name="student_id">学生学号</param>
        /// <param name="problem_id">小题ID</param>
        /// <returns></returns>
        static public Score_detail GetScore_detail(string student_id, int problem_id)
        {
            using (scoremsdbEntities db = new scoremsdbEntities())
            {
                Score_detail model = new Score_detail();
                var score_detail = db.score_detail.FirstOrDefault(x => x.student_id == student_id && x.problem_id == problem_id);
                model.student_id = score_detail.student_id;
                model.problem_id = score_detail.problem_id;
                model.score_detail_points = score_detail.score_detail_points;
                return model;
            }
        }

        /// <summary>
        /// 添加分数
        /// </summary>
        /// <param name="course"></param>
        /// <returns>成功返回true</returns>
        static public bool AddScore_detail(Score_detail model)
        {
            try
            {
                using (scoremsdbEntities db = new scoremsdbEntities())
                {
                    db.score_detail.AddObject(new score_detail()
                    {
                        student_id = model.student_id,
                        problem_id = model.problem_id,
                        score_detail_points = model.score_detail_points
                    });
                    db.SaveChanges();
                }
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}
